package zzzhc.image.core;

import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;

public final class Util {

	private Util() {
	}

	public static String getHtml(HttpClient client, String url)
			throws IOException {
		GetMethod method = new GetMethod(url);
		try {
			client.executeMethod(method);
			return method.getResponseBodyAsString();
		} finally {
			method.releaseConnection();
		}
	}

	public static byte[] getData(HttpClient client, String url,
			String refererUrl) throws IOException {
		GetMethod method = new GetMethod(url);
		if (refererUrl != null && !"".equals(refererUrl)) {
			method.addRequestHeader("Referer", refererUrl);
		}
		try {
			client.executeMethod(method);
			return method.getResponseBody();
		} finally {
			method.releaseConnection();
		}
	}
}
